import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/pages/my/controller/statement_ctr.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';

///富文本渲染的各种协议页面
class Statement extends StatelessWidget {
  Statement({super.key});

  final StatementController controller = Get.put(StatementController());

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: controller.titleText,
      iconType: IconType.back,
      isShowPadding: true,
      children: [
        Obx(() => _htmlContainerWidget()),
        if (controller.linkType == RichTextLinkType.aboutUs)
          Positioned(
            bottom: 0,
            child: Container(
              /// 显示app 的版本号
              color: Colors.white,
              width: ScreenUtil().screenWidth,
              padding: const EdgeInsets.all(8.0),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Obx(() {
                    return Text('当前版本：${controller.appVersion.value}');
                  }),
                  const SizedBox(height: 5),
                  const Text('皖ICP16013134号-2A'),
                ],
              ),
            ),
          ),
      ],
    );
  }

  Widget _htmlContainerWidget() {
    logger.d('linkType xxx === ${controller.linkType}');
    switch (controller.linkType) {
      case RichTextLinkType.privacyPolicy:
        return controller.privacyPolicy.isEmpty ? emptyWidget() : HtmlWidget(controller.privacyPolicy.value);
      case RichTextLinkType.serviceTerm:
        return controller.serviceTerm.isEmpty ? emptyWidget() : HtmlWidget(controller.serviceTerm.value);
      case RichTextLinkType.userMsgList:
        return controller.userMsgList.isEmpty ? emptyWidget() : HtmlWidget(controller.userMsgList.value);
      case RichTextLinkType.shareList:
        return controller.shareList.isEmpty ? emptyWidget() : HtmlWidget(controller.shareList.value);
      case RichTextLinkType.aboutUs:
        return controller.aboutUs.isEmpty ? emptyWidget() : HtmlWidget(controller.aboutUs.value);
      case RichTextLinkType.presalePolicy:
        return controller.presalePolicy.isEmpty ? emptyWidget() : HtmlWidget(controller.presalePolicy.value);
      default:
        return emptyWidget();
    }
  }
}
